import * as PIXI from 'pixi.js'
import { categoryModule } from '@renderer/utils/bundle'
import { CATEGORY } from '@renderer/config'
import useDiyStore from '@renderer/store/modules/useDiyStore'
import useDiydataStore from '@renderer/store/modules/useDiydataStore'
import { getPixiData, setPixi } from '@renderer/store/modules/usePixiStore'
import param from '../param'
import { categoryText } from '@renderer/utils/textFactory'
export default async (): Promise<PIXI.Container<PIXI.ContainerChild>> => {
  const diyStore = useDiyStore()
  const diydataStore = useDiydataStore()
  const container = new PIXI.Container()
  await Promise.all(
    Object.entries(CATEGORY).map(async ([typeKey, categorys]) => {
      await Promise.all(
        Object.entries(categorys).map(async ([key]) => {
          const categoryContainerData = getPixiData(param.value.categoryKey[key]) // 类型数据
          const sprite = await categoryModule({
            type: typeKey,
            category: key,
          } as Wx.Card.Param)
          sprite.anchor.set(0.5)
          sprite.scale.set(0.5)
          sprite.position.set(0, 506 / 2 - 20)
          sprite.visible = diyStore.creationData.category === key
          categoryContainerData.rightCategory = sprite.uid // 将类别与右侧关联
          setPixi(sprite.uid, sprite)
          container.addChild(sprite)
        }),
      )
    }),
  )
  diydataStore.data.category.forEach((key) => {
    const categoryContainerData = getPixiData(diydataStore.getCategoryMap(key)) // 类型数据
    const text = categoryText(key)
    text.anchor.set(0.5)
    text.scale.set(0.5)
    text.position.set(0, 506 / 2 - 20)
    text.visible = diyStore.creationData.category === key
    categoryContainerData.rightCategory = text.uid // 将类别与右侧关联
    setPixi(text.uid, text)
    container.addChild(text)
  })
  return container
}
